package com.zjitc.servicesms.controller;

import com.zjitc.common.utils.RespBean;
import com.zjitc.servicesms.service.SmsService;
import com.zjitc.servicesms.utils.RandomUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: ${赵诚挚}
 * @Date: 2024/10/9 14:22
 */
@RestController
@RequestMapping("/servicesms/sms")
public class SmsController {
    @Autowired
    private SmsService smsService;

    @GetMapping("get/{phone}")
    @ApiOperation("发送短信")
    public RespBean getSms(@PathVariable String phone){
        String code = RandomUtils.getFourBitRandom();
        Map<String,Object> param = new HashMap<>();
        param.put("code",code);
        boolean getPhone = smsService.getPhone(param,phone);
        if (getPhone){
            return RespBean.success().data("code",code).msg("发送成功");
        }else {
            return RespBean.error(201,"发送失败");
        }
    }

}
